import { useUserInfoStore } from '@gis/lib/pinia/userInfo.js';
import { handleCommonRes } from '@gis/lib/utils/resolver.js';
import { BasicMarker } from '../../js/BasicMarker.js';
import { BasicMarkers } from '../../js/BasicMarkers.js';
import { getMarkerIcon } from '../../js/icon.js';
import { getDwcsCoordinateData } from '@gis/lib/api';
// import { showUnitDetails } from '@/views/reality-unit/js/unit-details-dialog';

const typeCodeEnum = {
  1: 'gy',
  2: 'xx',
  3: 'yy',
  7: 'pcs',
  8: 'xfd',
  10: 'jb',
  11: 'cyzt',
  12: 'ltzt',
  13: 'sxzt',
  21: 'yd',
  22: 'zs',
  23: 'hzp',
  24: 'yjd',
  25: 'ylqx',
  31: 'jlsydw',
  32: 'tzsbsydw',
  33: 'rzrkscqy',
  34: 'jyjcjg',
  '4_01': 'gd',
  '5_01': 'wl',
  '6_02': 'xx',
  '6_03': 'yy',
  '6_04': 'pcs',
  '6_05': 'xfd',
  '6_06': 'bsc',
  '6_07': 'sq',
  '6_09': 'dxmc',
  '6_10': 'gc',
  '6_11': 'wb',
  '6_12': 'ktv',
  '6_13': 'yqjc',
  '6_14': 'jslkzqd',
  '6_15': 'gongmu',
};

class Marker extends BasicMarker {
  constructor({ map, data }) {
    super({ map, data });
    /* this.type: 这个type主要用于筛选,需要和filter-legend里面的type相对应 */
    this.type = typeCodeEnum[data.type_code];
    super.create();
  }
  getIcon() {
    return getMarkerIcon(this.type);
  }
  onClick() {
    // showUnitDetails(this.data);
  }
}

export default class Dwcs extends BasicMarkers {
  constructor({ map }) {
    super();
    this.map = map;
  }
  createMarker(data) {
    return new Marker({ map: this.map, data });
  }
  async getDataAsync() {
    const { area_code } = useUserInfoStore();
    const params = {
      /* 单位类型: 4,5,6, 场所类型: 1公园、2学校、3医院、7派出所、8消防队、10酒吧 */
      type: '4,5,6',
      dType: 'dwcs',
      area_code: area_code,
    };
    const data = await handleCommonRes(getDwcsCoordinateData, params);
    return data.map((item) => Object.assign(item, { lnglat: [item.longitude, item.latitude] }));
  }
}
